package com.aci.test.wordfreq.sort.impl;

import java.util.Iterator;
import java.util.List;

import com.aci.test.wordfreq.sort.IWordsListSelector;
import com.google.common.collect.Lists;

public class FirstElementsSelector implements IWordsListSelector {

	private int selectionSize;

	public FirstElementsSelector(int selectionSize) {
		this.selectionSize = selectionSize;
	}

	@Override
	public Iterable<String> select(Iterable<String> words) {
		List<String> selection = Lists.newArrayList();
		Iterator<String> wordsIterator = words.iterator();
		while (wordsIterator.hasNext() && selection.size() < selectionSize) {
			selection.add(wordsIterator.next());
		}
		return selection;
	}

}
